package com.exahq.controller;


import com.exahq.common.lang.Result;
import com.exahq.entity.Companytype;
import com.exahq.entity.Industry;
import com.exahq.entity.Organizations;
import com.exahq.service.IndustryService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lhq
 * @since 2021-02-02
 */
@RestController
@RequestMapping("/industry")
public class IndustryController {

    @Autowired
    IndustryService industryService;

    /**
     * 查询所有信息
     * @return
     */
    @RequestMapping("/finaAll")
    public Result fianall(){
        List<Industry> list = industryService.list();
        return Result.succ(list);
    }
    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public Result del(@PathVariable(name = "id") Integer id) {
        return Result.succ( industryService.delete(id));
    }

    /**
     * 详情查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result detail(@PathVariable(name = "id") Integer id) {
        Industry industry = industryService.getById(id);
        return Result.succ(industry);
    }
    /**
     * 增加/修改
     * @param industry
     * @return
     */
    @PostMapping("saveEdit")
    public Result saveEdit(@RequestBody Industry industry){
        if (industry!=null && !industry.equals("")){
            if (industry.getIuId() == null){
                boolean b = industryService.save(industry);
                if (b){
                    return Result.succ("新添成功",b);
                }
            }else {
                if (industryService.saveOrUpdate(industry))
                    return Result.succ("修改成功",industryService.saveOrUpdate(industry));
            }
        }
        return Result.succ(null);
    }
}
